package com.jsonpfy.webservices;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jsonpfy.operations.Put;

@SuppressWarnings("serial")
public class PutServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		String kind = request.getParameter("kind");

		String ID = request.getParameter("ID");

		String[] fieldsKind = request.getParameterValues("fieldsKind");

		String[] fieldsName = request.getParameterValues("fieldsName");

		String[] fieldsValue = request.getParameterValues("fieldsValue");

		Put.doPut(kind, ID, fieldsKind, fieldsName, fieldsValue);

		String answer = Utilities.getCallback(request.getParameter("callback"),
				"OK");

		response.getWriter().println(answer);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		String kind = request.getParameter("kind");

		String ID = request.getParameter("ID");

		String[] fieldsKind = request.getParameterValues("fieldsKind");

		String[] fieldsName = request.getParameterValues("fieldsName");

		String[] fieldsValue = request.getParameterValues("fieldsValue");

		Put.doPut(kind, ID, fieldsKind, fieldsName, fieldsValue);

		String answer = Utilities.getCallback(request.getParameter("callback"),
				"OK");

		response.getWriter().println(answer);
	}
}
